﻿package com.lmm;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
 
/**
 * 记录路由信息，它保存了一张禁忌表，和簇内节点信息。它随着移动agent移动而变化。
 * 属于移动agent 的数据结构的一部分。
 * @author Dts
 *
 */
public class ExchangeRoadModel implements Serializable{
	/**
	 * 串行化
	 */
	private static final long serialVersionUID = -5584123233487839985L;
   
	private List<Object> visitWayList;                   //待访问的路由信息
	private List<Object> arriveWayList;       			 //已访问的路由信息
	private List<Object> visitRecordList;       			 //已访问的路由信息
	private String courrentPath;	                     //当前节点
	private String changeData = "";
	
	/**
	 * 初始化禁忌表
	 */
	public void resetArriveWay()
	{
		visitRecordList = new ArrayList<Object>();
		arriveWayList = new ArrayList<Object>();
	}

	/**
     * 采用蚁群算法计算路径
     * @return
     */
	public String getWay()	
	{		
		int totalSize = getVisitWaySize();
		int index  = (int) (Math.random() * totalSize);		
		Object way = null;	
		if(index < getVisitWaySize())
		{
			way = visitWayList.get(index);
			visitWayList.remove(index);
			arriveWayList.add(way);
		}
		else
		{
			System.out.println("All Way is Runing");			
		}
		visitRecordList.add(way);
		return way.toString();		
	}
	
	
	public void printRoad(String homeUrl)
	{
		System.out.println(AgentConfig.V_STR_SPLITCHAR);
		System.out.println("The Visiting Routine is:");
		System.out.println(homeUrl);
		for(Object obj:visitRecordList)
		{
			if(obj != null)
				System.out.println(obj.toString());
		}
		System.out.println(homeUrl);
	}
	/**
	 * 获取系统包含的总路径数量
	 */
	public int getVisitWaySize()
	{
		return visitWayList.size();
	}
	public void setVisitWayList(List<Object> list)
	{
		visitWayList = list;
	}

	public String getCourrentPath() {
		return courrentPath;
	}

	public void setCourrentPath(String courrentPath) {
		this.courrentPath = courrentPath;
	}	
	
	public void putData(String data)
	{
		changeData = this.changeData.concat(data);
	}
	public String getData()
	{
		return this.changeData;		
	}
}
